<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%weather}}`.
 */
class m240524_120003_create_weather_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('weather', [
            'id' => $this->primaryKey(),
            'regionId' => $this->integer(),
            'regionName' => $this->string(),
            'temperature' => $this->float(),
            'humidity' => $this->float(),
            'windSpeed' => $this->float(),
            'weatherCondition' => $this->string(),
            'precipitationAmount' => $this->float(),
            'measurementDateTime' => $this->timestamp(),
            'weatherForecast' => $this->string(),
        ]);

        // Добавляем внешний ключ для regionId
        $this->addForeignKey(
            'fk-weather-regionId',
            'weather',
            'regionId',
            'region',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
          // Удаляем внешний ключ
          $this->dropForeignKey('fk-weather-regionId', 'weather');

          $this->dropTable('weather');
    }
}
